package com.lwy.qiuchao.field.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.lwy.qiuchao.field.entity.FieldEntity;
import com.lwy.common.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.lwy.qiuchao.field.entity.CityEntity;
import com.lwy.qiuchao.field.service.CityService;
import com.lwy.common.utils.PageUtils;


/**
 * 
 *
 * @author lwy
 * @email ${email}
 * @date 2020-12-01 14:41:42
 */
@RestController
@RequestMapping("field/city")
public class CityController {
    @Autowired
    private CityService cityService;

    //查询当前城市的球场数量
    @GetMapping("/fieldCount/{cityId}")
    public R fieldCount(@PathVariable("cityId") Long cityId ){
        List<FieldEntity> fieldEntities = cityService.QueryFieldCount(cityId);
        return R.ok().put("fieldEntities",fieldEntities);
    }

    //添加城市
    @GetMapping("/add")
    public R addCity(@RequestBody CityEntity cityEntity){
        cityService.addCity(cityEntity);
        return R.ok();
    }

    /**
     * 列表
     */
    @RequestMapping("/list")
    //@RequiresPermissions("field:city:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = cityService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{cityId}")
   // @RequiresPermissions("field:city:info")
    public R info(@PathVariable("cityId") Long cityId){
		CityEntity city = cityService.getById(cityId);

        return R.ok().put("city", city);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions("field:city:save")
    public R save(@RequestBody CityEntity city){
        
		cityService.save(city);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("field:city:update")
    public R update(@RequestBody CityEntity city){
		cityService.updateById(city);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("field:city:delete")
    public R delete(@RequestBody Long[] cityIds){
		cityService.removeByIds(Arrays.asList(cityIds));
		return R.ok();
    }

}
